﻿using EasyTest.Shared.EnumType;
using EasyTest.Shared.TestAttribute;
using EasyTest.Shared.外部访问;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ZLGCANoptimize
{
    /***************************************************************************
    version:1.0
    创建人:xianle
    创建时间:2025/2/18 10:59:05
    *描述：
    *修 改 人：  
    *修改时间：  
    *修改描述：
   *=====================================================================*/
    public class 标定
    {
        private static bool IsValidYYMMDD(string timeString)
        {
            if (string.IsNullOrEmpty(timeString) || timeString.Length != 6)
            {
                return false;
            }

            DateTime dateValue;
            string pattern = "yyMMdd";
            return DateTime.TryParseExact(timeString, pattern, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateValue);
        }
        [ExposedMethodAttribute("")]
        public bool 读ECU生产日期F18B(int 通道, out bool 合法日期, out string 生产日期, out string 信息)
        {
            生产日期 = "";
            合法日期 = false;
            信息 = "";
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";// "06 2E F1 8B 24 07 26 00";
                    return false;
                }
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 300, 100);
                zLGCANHelper.SentData(通道, 0x761, "03 22 F1 8B 00 00 00 00", true, SendType.正常发送);
                Thread.Sleep(50);
                zLGCANHelper.SentData(通道, 0x761, "30 08 14 00 00 00 00 00", true, SendType.正常发送);
                Thread.Sleep(80);
                zLGCANHelper.SentData(通道, 0x761, "30 08 14 00 00 00 00 00", true, SendType.正常发送);

                zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 3, 1500);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                Thread.Sleep(50);
                string[] hexValues = new string[5];
                int num = 0;
                bool ok10 = false;
                bool ok21 = false;
                foreach (string s in datas)
                {
                    if (s.Trim().StartsWith("06"))
                    {
                        ok10 = true;
                        for (int i = 0; i < s.Split(' ').Length; i++)
                        {
                            if (i < 4 || i > 7) continue;
                            hexValues[num] = s.Split(' ')[i];
                            num++;
                        }
                    }
                }
                信息 = string.Join(",", datas);
                生产日期 = String.Join("", hexValues.ToList().GetRange(0, 3)).Trim();

                //判断是否为日期
                合法日期 = IsValidYYMMDD(生产日期);
                //return isValid;

                //修改判断，只要是积极反馈即可,2024-11-07
                var ss = string.Join("", datas).Replace(" ", "");
                if (ss.Contains("62F18B"))
                {
                    return true;  //积极反馈
                }

                return false;
            }
            catch (Exception ex)
            {
                信息 = ex.Message;
                //LogHelper.Error($"[ZLGCANoptimize.读取生产日期]异常，{ex.Message}，{ex.StackTrace}");
                eLog.AddLog($"[读取生产日期]异常，{ex.Message}，{ex.StackTrace}", eMsgType.Error);
            }
            return false;
        }
        [ExposedMethodAttribute("")]
        public bool 读VEHICLE_CONFIG_C_C00C(int 通道,  out string 数据字, out int 字节长度, out string 信息)
        {

            数据字 = "";
            字节长度 = 0;
            信息 = "";
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                _ = zLGCANHelper.RecvData(通道, 0x769, 300, 100);
                Thread.Sleep(50);
                bool r1 = false;
                for (int i = 0; i < 5; i++)
                {
                    r1 = zLGCANHelper.SentData(通道, 0x761, "03 22 C0 0C 00 00 00 00", true, SendType.正常发送);
                    Thread.Sleep(50);
                    zLGCANHelper.SentData(通道, 0x761, "30 08 14 00 00 00 00 00", true, SendType.正常发送);
                    if (r1)
                    {
                        break;
                    }
                }
                if (!r1)
                {
                    信息 = "发送失败...";

                    return false;
                }
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 3, 1500);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                bool ok10 = false;
                bool ok21 = false;
                bool ok22 = false;
                //07 62 C0 0C FF 02 FF FF
                foreach (string s in datas)
                {
                    if (s.Trim().StartsWith("07 62 C0 0C"))
                    {
                        var SD= s.Split(' ');
                        ok10 = true;
                        if (SD.Length > 5)
                        {
                            数据字 = SD[5];
                        }
                       
                    }
                 
                    
                }
                string[] hexValues = new string[16];
                int num = 0;
               
                /*
                    10 13 62 F1 21 11 79 65
                    21 81 03 AA AA AA AA AA
                    22 00 00 00 00 FF FF AA
                */
              
               
                信息 = string.Join(",", datas);
               

                return ok10;
            }
            catch (Exception ex)
            {
                信息 = ex.Message;
                throw;
            }
        }
        [ExposedMethodAttribute("")]
        public bool 读VEHICLE_CONFIG_N_C017(int 通道, out string 数据字, out int 字节长度, out string 信息)
        {

            数据字 = "";
            字节长度 = 0;
            信息 = "";
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                _ = zLGCANHelper.RecvData(通道, 0x769, 300, 100);
                Thread.Sleep(50);
                bool r1 = false;
                for (int i = 0; i < 5; i++)
                {
                    r1 = zLGCANHelper.SentData(通道, 0x761, "03 22 C0 17 00 00 00 00", true, SendType.正常发送);
                    Thread.Sleep(50);
                    zLGCANHelper.SentData(通道, 0x761, "30 08 14 00 00 00 00 00", true, SendType.正常发送);
                    if (r1)
                    {
                        break;
                    }
                }
                if (!r1)
                {
                    信息 = "发送失败...";

                    return false;
                }
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 3, 1500);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                bool ok10 = false;
                bool ok21 = false;
                bool ok22 = false;
                //07 62 C0 0C FF 02 FF FF
                foreach (string s in datas)
                {
                    if (s.Trim().StartsWith("07 62 C0 17"))
                    {
                        var SD = s.Split(' ');
                        ok10 = true;
                        if (SD.Length > 5)
                        {
                            数据字 = SD[5];
                        }

                    }


                }
                string[] hexValues = new string[16];
                int num = 0;

                信息 = string.Join(",", datas);


                return ok10;
            }
            catch (Exception ex)
            {
                信息 = ex.Message;
                throw;
            }
        }

        [ExposedMethodAttribute("")]
        public bool 读VEHICLE_CONFIG_H_C011(int 通道, out string 数据字, out int 字节长度, out string 信息)
        {

            数据字 = "";
            字节长度 = 0;
            信息 = "";
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                _ = zLGCANHelper.RecvData(通道, 0x769, 300, 100);
                Thread.Sleep(50);
                bool r1 = false;
                for (int i = 0; i < 5; i++)
                {
                    r1 = zLGCANHelper.SentData(通道, 0x761, "03 22 C0 11 00 00 00 00", true, SendType.正常发送);
                    Thread.Sleep(50);
                    zLGCANHelper.SentData(通道, 0x761, "30 08 14 00 00 00 00 00", true, SendType.正常发送);
                    if (r1)
                    {
                        break;
                    }
                }
                if (!r1)
                {
                    信息 = "发送失败...";

                    return false;
                }
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 3, 1500);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                bool ok10 = false;
                bool ok21 = false;
                bool ok22 = false;
                //07 62 C0 0C FF 02 FF FF
                foreach (string s in datas)
                {
                    if (s.Trim().StartsWith("07 62 C0 11"))
                    {
                        var SD = s.Split(' ');
                        ok10 = true;
                        if (SD.Length > 5)
                        {
                            数据字 = SD[5];
                        }

                    }


                }
                string[] hexValues = new string[16];
                int num = 0;

                信息 = string.Join(",", datas);


                return ok10;
            }
            catch (Exception ex)
            {
                信息 = ex.Message;
                throw;
            }
        }
        [ExposedMethodAttribute("")]
        public bool 读默认选中_C002(int 通道, out string 数据字, out int 字节长度, out string 信息)
        {

            数据字 = "";
            字节长度 = 0;
            信息 = "";
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                _ = zLGCANHelper.RecvData(通道, 0x769, 300, 100);
                Thread.Sleep(50);
                bool r1 = false;
                for (int i = 0; i < 5; i++)
                {
                    r1 = zLGCANHelper.SentData(通道, 0x761, "03 22 C0 02 00 00 00 00", true, SendType.正常发送);
                   
                    Thread.Sleep(50);
                    zLGCANHelper.SentData(通道, 0x761, "30 08 14 00 00 00 00 00", true, SendType.正常发送);
                    if (r1)
                    {
                        break;
                    }
                }
                if (!r1)
                {
                    信息 = "发送失败...";

                    return false;
                }
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 3, 1500);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                bool ok10 = false;
                bool ok21 = false;
                bool ok22 = false;
                //07 62 C0 0C FF 02 FF FF
                foreach (string s in datas)
                {
                    if (s.Trim().StartsWith("07 62 C0 02"))
                    {
                        var SD = s.Split(' ');
                        ok10 = true;
                        if (SD.Length > 6)
                        {
                            数据字 = SD[6];
                        }

                    }


                }
                string[] hexValues = new string[16];
                int num = 0;
                信息 = string.Join(",", datas);
                return ok10;
            }
            catch (Exception ex)
            {
                信息 = ex.Message;
                throw;
            }
        }

        /// <summary>
        /// AH4EM : FF 06 FF FF
        /// AP4ER : FF 02 FF FF
        /// </summary>
        /// <param name="通道"></param>
        /// <param name="返回信息"></param>
        /// <param name="ReadData"></param>
        /// <param name="PN"></param>
        /// <returns></returns>
        [ExposedMethodAttribute("")]
        public bool 写VEHICLE_CONFIG_C_C00C(int 通道, out string 返回信息, out string ReadData, string PN = "02")
        {
            返回信息 = string.Empty;
            ReadData = "";
            string str= $"07 2E C0 0C FF {PN} FF FF";
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    返回信息 = "启动can设备失败";//2E  写，22读
                    return false;
                }
                bool OK = false;
                for (int i = 0; i < 1; i++)
                {
                    OK = Can.解密(通道, new List<ZCAN_Receive_Data>(), out 返回信息, "01");
                    if (OK)
                    {
                        break;
                    }
                    //Thread.Sleep(50);
                }
                if (!OK)
                {
                   // 返回信息 = "解密失败";
                    return false;
                }


                //发送报文
                bool result1 = false;
             
                result1 = zLGCANHelper.SentData(通道, 0x761, str, true, SendType.正常发送);
                eLog.AddLog($"写VEHICLE_CONFIG_C_C00C命令：{str}", eMsgType.Debug);
                if (!result1)
                {
                    返回信息 = "发送数据失败,写VEHICLE_CONFIG_C_C00C失败";
                    return false;
                }
                Thread.Sleep(50);
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 3, 1500);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                eLog.AddLog($"写VEHICLE_CONFIG_C_C00C响应：{string.Join(",", datas)}", eMsgType.Debug);
                bool ok10=false;
                foreach (string s in datas)
                {
                    if (s.Trim().StartsWith("03 6E C0 0C"))
                    {
                        返回信息 = "写VEHICLE_CONFIG_C_C00C成功";
                        ok10 =true;
                    }
                }
                ReadData= string.Join(",", datas);
              

                
                return ok10;
            }
            catch (Exception ex)
            {
                返回信息 = ex.Message;
                // LogHelper.Error($"[AVSV.打开AVSV]异常，{ex.Message}，{ex.StackTrace}");
                eLog.AddLog($"[写VEHICLE_CONFIG_C_C00C]异常，{ex.Message}，{ex.StackTrace}", eMsgType.Error);
            }
            return false;
        }

        /// <summary>
        /// FF 04 FF FF
        /// </summary>
        /// <param name="通道"></param>
        /// <param name="返回信息"></param>
        /// <param name="ReadData"></param>
        /// <param name="PN"></param>
        /// <returns></returns>
        [ExposedMethodAttribute("")]
        public bool 写VEHICLE_CONFIG_N_C017(int 通道, out string 返回信息, out string ReadData, string PN = "04")
        {
            返回信息 = string.Empty;
            ReadData = "";
            string str = $"07 2E C0 17 FF {PN} FF FF";
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    返回信息 = "启动can设备失败";//2E  写，22读
                    return false;
                }
                bool OK = false;
                for (int i = 0; i < 1; i++)
                {
                    OK = Can.解密(通道, new List<ZCAN_Receive_Data>(), out 返回信息, "01");
                    if (OK)
                    {
                        break;
                    }
                    //Thread.Sleep(50);
                }
                if (!OK)
                {
                    // 返回信息 = "解密失败";
                    return false;
                }


                //发送报文
                bool result1 = false;

                result1 = zLGCANHelper.SentData(通道, 0x761, str, true, SendType.正常发送);
                eLog.AddLog($"写VEHICLE_CONFIG_N_C017命令：{str}", eMsgType.Debug);
                if (!result1)
                {
                    返回信息 = "发送数据失败,写VEHICLE_CONFIG_N_C017失败";
                    return false;
                }
                Thread.Sleep(50);
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 3, 1500);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                eLog.AddLog($"写VEHICLE_CONFIG_N_C017响应：{string.Join(",", datas)}", eMsgType.Debug);
                bool ok10 = false;
                foreach (string s in datas)
                {
                    if (s.Trim().StartsWith("03 6E C0 17"))
                    {
                        返回信息 = "写VEHICLE_CONFIG_N_C017成功";
                        ok10 = true;
                    }
                }
                ReadData = string.Join(",", datas);



                return ok10;
            }
            catch (Exception ex)
            {
                返回信息 = ex.Message;
                // LogHelper.Error($"[AVSV.打开AVSV]异常，{ex.Message}，{ex.StackTrace}");
                eLog.AddLog($"[写VEHICLE_CONFIG_N_C017]异常，{ex.Message}，{ex.StackTrace}", eMsgType.Error);
            }
            return false;
        }
        /// <summary>
        /// FF FF FF 00
        /// </summary>
        /// <param name="通道"></param>
        /// <param name="返回信息"></param>
        /// <param name="ReadData"></param>
        /// <param name="PN"></param>
        /// <returns></returns>
        [ExposedMethodAttribute("")]
        public bool 写VEHICLE_CONFIG_H_C011(int 通道, out string 返回信息, out string ReadData, string PN = "FF")
        {
            返回信息 = string.Empty;
            ReadData = "";
            string str = $"07 2E C0 11 FF {PN} FF 00";
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    返回信息 = "启动can设备失败";//2E  写，22读
                    return false;
                }
                bool OK = false;
                for (int i = 0; i < 1; i++)
                {
                    OK = Can.解密(通道, new List<ZCAN_Receive_Data>(), out 返回信息, "01");
                    if (OK)
                    {
                        break;
                    }
                   // Thread.Sleep(50);
                }
                if (!OK)
                {
                    // 返回信息 = "解密失败";
                    return false;
                }


                //发送报文
                bool result1 = false;

                result1 = zLGCANHelper.SentData(通道, 0x761, str, true, SendType.正常发送);
                eLog.AddLog($"写VEHICLE_CONFIG_H命令：{str}", eMsgType.Debug);
                if (!result1)
                {
                    返回信息 = "发送数据失败,写VEHICLE_CONFIG_H_C011失败";
                    return false;
                }
                Thread.Sleep(50);
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 3, 1500);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                eLog.AddLog($"写VEHICLE_CONFIG_H命令响应：{string.Join(",", datas)}", eMsgType.Debug);
                bool ok10 = false;
                foreach (string s in datas)
                {
                    if (s.Trim().StartsWith("03 6E C0 11"))
                    {
                        返回信息 = "写VEHICLE_CONFIG_H_C011成功";
                        ok10 = true;
                    }
                }
                ReadData = string.Join(",", datas);



                return ok10;
            }
            catch (Exception ex)
            {
                返回信息 = ex.Message;
                // LogHelper.Error($"[AVSV.打开AVSV]异常，{ex.Message}，{ex.StackTrace}");
                eLog.AddLog($"[写VEHICLE_CONFIG_H_C011]异常，{ex.Message}，{ex.StackTrace}", eMsgType.Error);
            }
            return false;
        }
        /// <summary>
        /// 测试需标定：FF FF 0B FF，测试完成后还原成默认值：FF FF FF FF
        /// </summary>
        /// <param name="通道"></param>
        /// <param name="返回信息"></param>
        /// <param name="ReadData"></param>
        /// <param name="PN"></param>
        /// <returns></returns>
        [ExposedMethodAttribute("")]
        public bool 写默认选中_C002(int 通道, out string 返回信息, out string ReadData, string PN = "0B")
        {
            返回信息 = string.Empty;
            ReadData = "";//FF FF 0B FF
            string str = $"07 2E C0 02 FF FF {PN} FF";
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    返回信息 = "启动can设备失败";//2E  写，22读
                    return false;
                }
                bool OK=false;
                //Thread.Sleep(100);
                for (int i = 0; i < 1; i++)
                {
                    OK = Can.解密(通道, new List<ZCAN_Receive_Data>(), out 返回信息, "01");
                    if (OK)
                    {
                       break;
                    }
                  //  Thread.Sleep(50);
                }
                
                if (!OK)
                {
                    // 返回信息 = "解密失败";
                    return false;
                }


                //发送报文
                bool result1 = false;

                result1 = zLGCANHelper.SentData(通道, 0x761, str, true, SendType.正常发送);
                eLog.AddLog($"写默认选中命令：{str}", eMsgType.Debug);
                if (!result1)
                {
                    返回信息 = "发送数据失败,写默认选中_C002失败";
                    return false;
                }
                Thread.Sleep(50);
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 3, 1500);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                eLog.AddLog($"写默认选中命令响应：{string.Join(",", datas)}", eMsgType.Debug);
                bool ok10 = false;
                foreach (string s in datas)
                {
                    if (s.Trim().StartsWith("03 6E C0 02"))
                    {
                        返回信息 = "写默认选中_C002成功";
                        ok10 = true;
                    }
                }
                ReadData = string.Join(",", datas);



                return ok10;
            }
            catch (Exception ex)
            {
                返回信息 = ex.Message;
                // LogHelper.Error($"[AVSV.打开AVSV]异常，{ex.Message}，{ex.StackTrace}");
                eLog.AddLog($"[写默认选中_C002]异常，{ex.Message}，{ex.StackTrace}", eMsgType.Error);
            }
            return false;
        }
        /// <summary>
        /// 生产日期根据SN获取 FFFFFF 例240218
        /// </summary>
        /// <param name="通道"></param>
        /// <param name="响应"></param>
        /// <param name="命令"></param>
        /// <param name="信息"></param>
        /// <returns></returns>
        [ExposedMethodAttribute("")]
        public bool 写ECU生产日期F18B(int 通道, out string 响应, out string 命令, out string 信息)
        {
            信息 = "";
            响应 = "";
            命令 = $"06 2E F1 8B {DateTime.UtcNow.ToString("yy")} {DateTime.UtcNow.ToString("MM")} {DateTime.UtcNow.ToString("dd")} AA";
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                _ = zLGCANHelper.RecvData(通道, 0x769, 1000, 100);
                bool OK = Can.解密(通道, new List<ZCAN_Receive_Data>(), out 信息, "62");
                if (!OK)
                {
                    信息 = "解密失败";
                    return false;
                }
                bool result1;
                result1 = zLGCANHelper.SentData(通道, 0x761, 命令, true, SendType.正常发送);
                eLog.AddLog($"写ECU生产日期命令：{命令}", eMsgType.Debug);
                if (!result1)
                {
                    信息 = "发送数据失败,写入生产日期失败";
                    return false;
                }
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 3, 1500);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                eLog.AddLog($"写ECU生产日期命令响应：{string.Join(",", datas)}", eMsgType.Debug);
                响应 = string.Join("\n", datas);
                if (datas.Length > 0)
                {
                    foreach (string s in datas)
                    {
                        if (s.Trim().StartsWith("03 6E F1 8B"))
                        {
                            信息 = "写入生产日期成功";
                            return true;
                        }
                    }
                }

                信息 = "写入生产日期失败";
            }
            catch (Exception ex)
            {
                信息 = ex.Message;
            }
            return false;
        }

        [ExposedMethodAttribute("")]
        public bool 写C02C(int 通道, out string 返回信息, out string ReadData, string PN = "FF")
        {
            返回信息 = string.Empty;
            ReadData = "";//01 01 01 01
            string str = $"07 2E C0 2C 01 01 01 01";
            //eLog.AddLog($"写C02C: {str}", eMsgType.Info);
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    返回信息 = "启动can设备失败";//2E  写，22读
                    return false;
                }
                bool OK = false;
                for (int i = 0; i < 1; i++)
                {
                    OK = Can.解密(通道, new List<ZCAN_Receive_Data>(), out 返回信息, "01");
                    if (OK)
                    {
                        break;
                    }
                    // Thread.Sleep(50);
                }
                if (!OK)
                {
                    // 返回信息 = "解密失败";
                    return false;
                }


                //发送报文
                bool result1 = false;

                result1 = zLGCANHelper.SentData(通道, 0x761, str, true, SendType.正常发送);
                eLog.AddLog($"写C02C响应：{str}", eMsgType.Debug);
                if (!result1)
                {
                    返回信息 = "发送数据失败,写C02C失败";
                    return false;
                }
                Thread.Sleep(50);
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 3, 1500);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                eLog.AddLog($"写C02C响应：{string.Join(",", datas)}", eMsgType.Debug);
                bool ok10 = false;
                foreach (string s in datas)
                {
                    if (s.Trim().StartsWith("03 6E C0 2C"))
                    {
                        返回信息 = "写C02C成功";
                        ok10 = true;
                    }
                }
                ReadData = string.Join(",", datas);

                return ok10;
            }
            catch (Exception ex)
            {
                返回信息 = ex.Message;
                // LogHelper.Error($"[AVSV.打开AVSV]异常，{ex.Message}，{ex.StackTrace}");
                eLog.AddLog($"[写C02C]异常，{ex.Message}，{ex.StackTrace}", eMsgType.Error);
            }
            return false;
        }

        [ExposedMethodAttribute("")]
        public bool 读C02C(int 通道, out string 数据字, out int 字节长度, out string 信息)
        {

            数据字 = "";
            字节长度 = 0;
            信息 = "";
            try
            {
                if (!数据.初始化(通道, out ZLGCANHelper zLGCANHelper))
                {
                    信息 = "启动can设备失败";
                    return false;
                }
                _ = zLGCANHelper.RecvData(通道, 0x769, 300, 100);
                Thread.Sleep(50);
                bool r1 = false;
                for (int i = 0; i < 5; i++)
                {
                    r1 = zLGCANHelper.SentData(通道, 0x761, "03 22 C0 2C 00 00 00 00", true, SendType.正常发送);
                    eLog.AddLog($"读C02C发送：03 22 C0 2C 00 00 00 00", eMsgType.Debug);
                    Thread.Sleep(50);
                    zLGCANHelper.SentData(通道, 0x761, "30 08 14 00 00 00 00 00", true, SendType.正常发送);
                    if (r1)
                    {
                        break;
                    }
                }
                if (!r1)
                {
                    信息 = "发送失败...";

                    return false;
                }
                List<ZCAN_Receive_Data> zCAN_Receive_Datas = zLGCANHelper.RecvData(通道, 0x769, 3, 1500);
                string[] datas = ZLGCanTool.GetData(zCAN_Receive_Datas);
                eLog.AddLog($"读C02C响应：{string.Join(",", datas)}", eMsgType.Debug);
                bool ok10 = false;
                bool ok21 = false;
                bool ok22 = false;
                foreach (string s in datas)
                {
                    if (s.Trim().StartsWith("07 62 C0 2C"))
                    {
                        var SD = s.Split(' ');
                        ok10 = true;
                        if (SD.Length > 5)
                        {
                            数据字 = SD[5];
                        }

                    }


                }
                string[] hexValues = new string[16];
                int num = 0;

                信息 = string.Join(",", datas);


                return ok10;
            }
            catch (Exception ex)
            {
                信息 = ex.Message;
                throw;
            }
        }
    }
}
